package com.shr.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * leetcode 442
 * @author sevn
 *
 */
public class FindDuplicatesInArray {
    public static List<Integer> findDuplicates(int[] nums) {
    	int[] recordArray = new int[nums.length + 1];
        for(int i = 0;i<nums.length;i++){
        	recordArray[nums[i]] += 1;
        }
        List<Integer> duplicateArray = new ArrayList<Integer>();
        for(int i = 0;i<recordArray.length;i++){
        	if(recordArray[i] == 2){
        		duplicateArray.add(i);
        	}
        }
        return duplicateArray;
    }
    
	public static void main(String[] args) {
		int[] array = {4,3,2,7,8,2,3,1};
		List<Integer> results = findDuplicates(array);
		System.out.println(results);
	}
}
